package com.kgc.scd.controller;

import com.kgc.scd.annotation.RequestPermission;
import com.kgc.scd.annotation.RequestUser;
import com.kgc.scd.service.PlaceOrderService;
import com.kgc.scd.util.RequestResult;
import com.kgc.scd.util.UserAnno;
import io.swagger.annotations.*;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * Created On : 2022/6/20.
 * <p>
 * Author     : 98730
 * <p>
 * Description: PlaceOrderController
 */
@Slf4j
@RestController
@Api(tags = "19、下单操作入口")
public class PlaceOrderController {

    @Autowired
    private PlaceOrderService placeOrderService;

    @PostMapping("/PlaceOneOrderFeign")
    @RequestPermission
    @ApiOperation(value = "普通下单入口", notes = "根据订单编号、优惠券编号、用户地址进行下单操作")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId", value = "订单号"),
            @ApiImplicitParam(name = "innerId", value = "用户可用优惠券编号"),
            @ApiImplicitParam(name = "addrId", value = "地址编号")
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "SUCCESS"),
            @ApiResponse(code = 500, message = "FAIL")
    })
    public RequestResult<Map<String, Object>> PlaceOneOrderFeign(@RequestParam String orderId, @RequestParam(required = false) Integer innerId, @RequestParam(required = false) String addrId, @RequestUser UserAnno userAnno){
        return placeOrderService.PlaceOneOrder(orderId, innerId, addrId, userAnno);
    }

    @PostMapping("/PlaceOneSeckillOrderFeign")
    @RequestPermission
    @ApiOperation(value = "秒杀下单入口", notes = "根据订单编号、用户地址进行秒杀下单操作")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "orderId", value = "订单号"),
            @ApiImplicitParam(name = "addrId", value = "地址编号", required = false)
    })
    @ApiResponses({
            @ApiResponse(code = 200, message = "SUCCESS"),
            @ApiResponse(code = 500, message = "FAIL")
    })
    public RequestResult<Map<String, Object>> PlaceOneSeckillOrderFeign(@RequestParam String orderId,
                                                           @RequestParam(required = false) String addrId,
                                                           @RequestUser UserAnno userAnno){
        return placeOrderService.PlaceOneSeckillOrder(orderId, addrId, userAnno);
    }
}
